package greate.project.event0;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class EmailService implements ApplicationListener<UserRegisterEvent> { // <1>

    @Override
    @Async("asyncExecutorService")// <3>
    public void onApplicationEvent(UserRegisterEvent event) { // <2>
        System.out.println(Thread.currentThread().getName());
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("[onApplicationEvent][给用户({}) 发送邮件]", event.getUsername());
    }
}